package com.yan.furns.filter;

import com.yan.furns.utils.JDBCUtilsByDruid;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author Yzb
 * @version 1.0
 */
public class TransactionFilter implements Filter {
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
		try {
			filterChain.doFilter(servletRequest, servletResponse);
			JDBCUtilsByDruid.commit();
		} catch (Exception e) {
			JDBCUtilsByDruid.rollback();
//			System.out.println("Reached There");
			throw new RuntimeException(e);
		}
	}

	@Override
	public void destroy() {

	}
}
